<template>
	<view class="container">
		<view class="top">
			<view class="above">
				<view class="" v-for="(item,index) in 3" :key="index">
					<image class="picture" src="../../static/homepage/tdmckk.png" mode=""></image>
				</view>
			</view>
			<view class="below">
				<view class="" v-for="(item,index) in 4" :key="index">
					<image class="picture" src="../../static/homepage/tdmckk.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="shuzi u-m-t-20">
			<view class="count u-p-t-36 u-p-b-10 u-flex u-row-center">
				<u-count-to class="count-to" ref="uCountTo" :autoplay="autoplay" :startVal="startVal" :endVal="endVal" :duration="duration"
				 :decimals="decimals" :bold="bold" :fontSize="fontSize" :color="color"></u-count-to>
				<text class="u-m-l-10">名优秀伙伴为您服务</text>
			</view>

			<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
				<u-form-item class="group" :label-width="200" :border-bottom="false" :label-position="labelPosition"
				 label="我是" prop="ws">
					<u-input :border="border" type="select" :select-open="selectShowWs" v-model="model.ws" placeholder="请选择"
					 placeholderStyle="color: #4B9CFF;" input-align="right" @click="selectShowWs = true"></u-input>
				</u-form-item>
				<u-form-item class="group" :label-width="200" :border-bottom="false" :label-position="labelPosition"
				 label="我需要" prop="wxy">
					<u-input :border="border" type="select" :select-open="selectShowWxy" v-model="model.wxy" placeholder="请选择"
					 placeholderStyle="color: #4B9CFF;" input-align="right" @click="selectShowWxy = true"></u-input>
				</u-form-item>
				<u-form-item class="group" :label-width="200" :border-bottom="false" :label-position="labelPosition"
				 label="我意向" prop="wyx">
					<u-input :border="border" type="select" :select-open="selectShowWyx" v-model="model.wyx" placeholder="请选择"
					 placeholderStyle="color: #4B9CFF;" input-align="right" @click="selectShowWyx = true"></u-input>
				</u-form-item>
				<!-- <u-form-item class="u-m-l-30 u-m-r-30" :label-position="labelPosition" label="工作地点" prop="region" label-width="400">
					<u-input :border="border" type="select" :select-open="pickerShow" input-align="right" placeholderStyle="color: #0D1D36;" v-model="model.region" placeholder="请选择" @click="pickerShow = true"></u-input>
				</u-form-item> -->
				<u-form-item class="u-m-l-30 u-m-r-40" :label-width="200" :label-position="labelPosition" :border-bottom="false" label="工作地点" prop="region">
					<u-input type="select" :select-open="selectShowGzdd" v-model="model.region" placeholder="请选择" placeholderStyle="color: #0D1D36;"
					 input-align="right" @click="selectShowGzdd = true"></u-input>
				</u-form-item>
				<u-form-item class="u-m-l-30 u-m-r-30" :label-position="labelPosition" label="诚信保证金" label-width="400" prop="bzj">
					<u-radio-group v-model="model.bzj" @change="checkboxGroupChange" :width="radioCheckWidth" :wrap="radioCheckWrap">
						<u-radio shape="square"  v-model="item.checked" v-for="(item, index) in checkboxListTwo" :key="index" :name="item.name">{{ item.name }}</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="zsbzj" class="u-m-l-30 u-m-r-30" label-width="200" :label-position="labelPosition" label="" prop="cxbzj">
					<u-input :border="border" placeholder="请输入保证金金额  元" v-model="model.cxbzj" type="text" input-align="right"></u-input>
				</u-form-item>

				<view class="fgx1">

				</view>
				<u-form-item class="u-m-l-30 u-m-r-30" label-width="200" :label-position="labelPosition" label="关键字" prop="gjz">
					<u-input :border="border" placeholder="请输入" v-model="model.gjz" type="text" input-align="right"></u-input>
				</u-form-item>
				<u-form-item class="u-m-l-30 u-m-r-30" label-width="200" :label-position="labelPosition" label="屏蔽关键字" prop="pbgjz">
					<u-input :border="border" placeholder="请输入" v-model="model.pbgjz" type="text" input-align="right"></u-input>
				</u-form-item>
				<u-form-item class="u-m-l-30 u-m-r-40" :label-width="200" :label-position="labelPosition" :border-bottom="false" label="匹配时效" prop="ppsx">
					<u-input type="select" :select-open="selectShowPpsx" v-model="model.ppsx" placeholder="请选择 至" placeholderStyle="color: #0D1D36;"
					 input-align="right" @click="selectShowPpsx = true"></u-input>
				</u-form-item>
				<u-gap :bg-color="bgColor" :height="height" :margin-bottom="marginBottom"></u-gap>
				<view class="qtsm u-m-l-40 u-m-r-30 u-m-t-40">
					<image src="../../static/img/releasesm.png" style="width: 29rpx; height: 29rpx;" mode=""></image>
					<text class="hz">其他说明</text>
				</view>
				<u-form-item class="  zwpj u-m-l-30 u-m-r-30 " :label-position="labelPosition"  prop="qtsm">
					<u-input  type="textarea" :border="border" placeholder="请输入其他说明" v-model="model.qtsm" />
				</u-form-item>
			</u-form>
		</view>
		<u-gap :bg-color="bgColor" :height="height" :margin-top="marginTop" :margin-bottom="marginBottom"></u-gap>
		<view class="list u-m-t-50">
			<view class="u-flex u-row-between u-p-20">
				<view>
					<image src="../../static/img/qiye.png"></image>
					<text class="title u-m-l-30 ">企业要求</text>
				</view>
				<view>
					<button size="mini" @click="toAdd" class="add">添加</button>
				</view>
			</view>
			<u-cell-group :border="false">
				<u-cell-item v-if="model.qyxz != ''" :title="model.qyxz+','+model.qyzz+','+model.fwlx+','+model.qydz+','+model.rygm" class="u-p-l-40"></u-cell-item>
			</u-cell-group>
		</view>
		<view class="warp u-m-t-20 u-p-30">
			<u-button class="button" @click="submit">马上为我匹配</u-button>
			<!--弹出框-->
			<u-select mode="single-column" :list="wsList" v-model="selectShowWs" @confirm="selectConfirmWs"></u-select>
			<u-select mode="single-column" :list="wxyList" v-model="selectShowWxy" @confirm="selectConfirmWxy"></u-select>
			<u-select mode="single-column" :list="wyxList" v-model="selectShowWyx" @confirm="selectConfirmWyx"></u-select>
			<u-select mode="single-column" :list="dataList" v-model="selectShowPpsx" @confirm="selectConfirmPpsx"></u-select>
			<u-select mode="single-column" :list="gzddList" v-model="selectShowGzdd" @confirm="selectConfirmGzdd"></u-select>
			<u-picker mode="region" v-model="pickerShow" @confirm="regionConfirm"></u-picker>
			<!--弹出框-->
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			let that = this;
			return {
				height: 20,
				bgColor: this.$u.color.bgColor,
				marginTop: 30,
				marginBottom: 30,
				show: false,
				mode: 'range',
				result: "请选择日期",
				startText: '开始',
				endText: '结束',
				rangeColor: '#2979ff',
				rangeBgColor: 'rgba(41,121,255,0.13)',
				activeBgColor: '#2979ff',
				btnType: 'primary',
				zsbzj: false,
				/**
				 * form验证
				 * */
				model: {
					ws: '',
					wxy: '',
					wyx: '',
					qymc: '',
					ppsx: '',
					region: '',
					cxbzj: '',
					gjz: '',
					pbgjz: '',
					qtsm: '',
					qyxz: '',
					qyzz: '',
					fwlx: '',
					qydz: '',
					rygm: '',
					bzj: '',
				},
				dataList: [
					{
						value: '2020-11-10',
						label: '2020-11-10'
					},
					{
						value: '2020-12-10',
						label: '2020-12-10'
					},
					{
						value: '2020-12-20',
						label: '2020-12-20'
					}
				],
				gzddList: [
					{
						value: '武汉',
						label: '武汉'
					},
					{
						value: '上海',
						label: '上海'
					},
					{
						value: '北京',
						label: '北京'
					}
				],
				selectList: [{
						value: '测试1',
						label: '测试1'
					},
					{
						value: '测试2',
						label: '测试2'
					},
					{
						value: '测试3',
						label: '测试3'
					}
				],
				params: {},
				wsList:[],
				wxyList:[],
				wyxList:[],
				checkboxListTwo: [

					{
						name: '需要',
						checked: false,
						disabled: false
					},
					{
						name: '不需要',
						checked: false,
						disabled: false
					},
				],
				rules: {
					zyp: [{
						required: false,
						message: '请选择招/应聘',
						trigger: 'change'
					}],
					// region: [
					// 	{
					// 		required: false,
					// 		message: '请选择地区',
					// 		trigger: 'change',
					// 	}
					// ],
					ws: [{
						required: false,
						message: '请选择我是',
						trigger: 'change'
					}],
					wxy: [{
						required: false,
						message: '请选择我需要',
						trigger: 'change'
					}],
					wyx: [{
						required: false,
						message: '请选择我意向',
						trigger: 'change'
					}]
				},
				required: false,
				border: false,
				check: false,
				region: '',
				selectStatus: 'close',
				selectShowZyp: false,
				selectShowWs: false,
				selectShowWxy: false,
				selectShowWyx: false,
				selectShowPpsx: false,
				selectShowQydy: false,
				selectShowGzdd: false,
				selectShowLyxy: false,
				pickerShow: false,
				labelPosition: 'left',
				codeTips: '',
				errorType: ['toast'],
				radio:'',
				radio1: '',
				radioCheckWidth: 'auto',
				radioCheckWrap: false,
				/**/

				/**
				 * 数字统计
				 * */
				startVal: 500,
				endVal: 500,
				separator: ',',
				decimals: 0,
				duration: 2000,
				autoplay: true,
				useEasing: true,
				current: 3,
				isStop: false,
				bold: false,
				fontSize: 24,
				color: '#fff',
				/**/
				keyIndex: 0,
				keywords: [{
					name: '企业',
					selected: true
				}, {
					name: '设计师',
					selected: false
				}, {
					name: '监理',
					selected: false
				}, {
					name: '大型企业',
					selected: false
				}, {
					name: '采购',
					selected: false
				}, {
					name: '监理',
					selected: false
				}]
			};
		},
		mounted() {},
		onShow(){
			this.wsDictionary();
			this.wxyDictionary();
			this.wyxDictionary();
		},
		onLoad(options){
			if(options.hy){
				let data = JSON.parse(decodeURIComponent(options.hy));
				this.model = data;
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			toAdd(){
				let data = this.model;
				data.type = "qiye";
				let query = encodeURIComponent(JSON.stringify(data))
				uni.navigateTo({
					url:"/pages/wisdomcommune/enterpriseAsk?data="+query
				})
				// uni.navigateTo({
				// 	url:"/pages/wisdomcommune/enterpriseAsk?type=qiye"
				// })
			},
			// checkbox选择发生变化
			checkboxGroupChange(e) {
				// debugger
				if(e==="需要"){
					this.zsbzj = true;
				}else{
					this.zsbzj = false;
				}
				
			},
			// 创建团队
			async submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
						// this.saveTeam();
						this.matching();
					} else {
						console.log('验证失败');
					}
				});
				
			},
			//企业匹配并新增
			async matching(){
				try {
				let reqBody = {};
				reqBody['area'] = this.model.region;
				reqBody['bond'] = parseInt(this.model.cxbzj);
				reqBody['bestKey'] = this.model.gjz;
				reqBody['blackKey'] = this.model.pbgjz;
				reqBody['remarks'] = this.model.qtsm;
				reqBody['expiryTime'] = this.model.ppsx;
				reqBody['iam'] = this.model.ws;
				reqBody['imean'] = this.model.wyx;
				reqBody['ineed'] = this.model.wxy;
				reqBody['xingzhi'] = this.model.qyxz;
				reqBody['zizhi'] = this.model.qyzz;
				reqBody['leixing'] = this.model.fwlx;
				reqBody['dizhi'] = this.model.qydz;
				reqBody['num'] = parseInt(this.model.rygm);
				let data = await this.$apis.enterpriseMatching(reqBody);
				if(data.code == 200){
					uni.showToast({
							title: "企业匹配成功",
							icon: 'none'
					});
					setTimeout(() => {
						this.$mRouter.switchTab({
							route:this.$mRoutesConfig.message
						});
					},2000)
					
				}else{
					uni.showToast({
						title: result.msg,
						icon: 'none'
					});
					return;
				}
				} catch (e) {
					console.log(e);
					this.submitBtnDis = false;
				}
			},
			async saveTeam(){
				let reqBody = {};
				reqBody['workplace'] = this.model.region;
				reqBody['bond'] = parseInt(this.model.bzj);
				let result = await this.$apis.saveTeam(reqBody);
				if(result.code==200){
					uni.showToast({
						title:"创建团队成功"
					})
					setTimeout(() => {
						this.$mRouter.switchTab({
							route:this.$mRoutesConfig.message
						});
					},1000)
				}
			},
			//查询匹配 我是  字典数据
			async wsDictionary(){
				let reqBody = {};
				reqBody['primary'] = "招投标";
				reqBody['secondary'] = "我是";
				let result = await this.$apis.findMatchingDictionary(reqBody);
				let list = result.data;
				for (let i = 0; i < list.length; i++) {
					let wsValue = {};
					wsValue['value'] = list[i].name;
					wsValue['label'] = list[i].name;
					this.wsList.push(wsValue)
				}
			},
			//查询匹配 我需要  字典数据
			async wxyDictionary(){
				let reqBody = {};
				reqBody['primary'] = "招投标";
				reqBody['secondary'] = "我需要";
				let result = await this.$apis.findMatchingDictionary(reqBody);
				let list = result.data;
				for (let i = 0; i < list.length; i++) {
					let wxyValue = {};
					wxyValue['value'] = list[i].name;
					wxyValue['label'] = list[i].name;
					this.wxyList.push(wxyValue)
				}
			},
			//查询匹配 我意向  字典数据
			async wyxDictionary(){
				let reqBody = {};
				reqBody['primary'] = "招投标";
				reqBody['secondary'] = "我意向";
				let result = await this.$apis.findMatchingDictionary(reqBody);
				let list = result.data;
				for (let i = 0; i < list.length; i++) {
					let wyxValue = {};
					wyxValue['value'] = list[i].name;
					wyxValue['label'] = list[i].name;
					this.wyxList.push(wyxValue)
				}
			},
			selectKey(e) {
				this.keywords[e].selected = !this.keywords[e].selected;
			},
			// 选择地区回调
			regionConfirm(e) {
				this.model.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
			},
			// 选择
			selectConfirmWs(e) {
				this.model.ws = '';
				e.map((val, index) => {
					this.model.ws += this.model.ws == '' ? val.label : '-' + val.label;
				});
			},
			selectConfirmWxy(e) {
				this.model.wxy = '';
				e.map((val, index) => {
					this.model.wxy += this.model.wxy == '' ? val.label : '-' + val.label;
				});
			},
			selectConfirmWyx(e) {
				this.model.wyx = '';
				e.map((val, index) => {
					this.model.wyx += this.model.wyx == '' ? val.label : '-' + val.label;
				});
			},
			selectConfirmPpsx(e) {
				this.model.ppsx = '';
				e.map((val, index) => {
					this.model.ppsx += this.model.ppsx == '' ? val.label : '-' + val.label;
				});
			},
			selectConfirmGzdd(e) {
				this.model.region = '';
				e.map((val, index) => {
					this.model.region += this.model.region == '' ? val.label : '-' + val.label;
				});
			},
			change(e) {
				if (this.mode == 'range') {
					this.result = e.startDate + " - " + e.endDate;
				} else {
					this.result = e.result;
				}
			},
			dianji() {
				this.show = true;
			},
			selectConfirmQydy(e) {
				this.model.qydy = '';
				e.map((val, index) => {
					this.model.qydy += this.model.qydy == '' ? val.label : '-' + val.label;
				});
			}
		}
	};
</script>
<style scoped lang="scss">
	page {
		background: #ffffff;
	}

	.top {
		width: 100%;
		height: 350rpx;
		background: linear-gradient(0deg, #AB61FF, #DF61FF);

		.above {
			display: flex;
			justify-content: center;
			margin-left: -46rpx;
		
			.picture {
				width: 117.8rpx;
				height: 137.4rpx;
				margin-left: 20rpx;
				margin-top: 20rpx;
			}
		}
		
		.below {
			display: flex;
			justify-content: center;
			margin-left: -46rpx;
			margin-top: -20rpx;
			.picture {
				width: 117.8rpx;
				height: 137.4rpx;
				margin-left: 20rpx;
				margin-top: 1rpx;
			}
		}
	}

	.count {
		margin-top: -50rpx;
		width: 100%;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 40rpx 40rpx 0rpx 0rpx;

		.count-to {
			font-size: 24rpx;
		}

		text {
			padding: 2rpx 12rpx;
			background: #ff9e21;
			color: #ffffff;
			font-size: 24rpx;
		}
	}

	.fgx {
		width: 100%;
		height: 20rpx;
		background-color: #F5F5F9;
		margin-top: 40rpx;
	}

	.fgx1 {
		width: 100%;
		height: 20rpx;
		background-color: #F5F5F9;
	}

	.group {
		padding: 6rpx 21rpx;
		background: #f1f7ff;
		border-radius: 6rpx;
		margin: 30rpx 30rpx 0 30rpx;
	}

	.button {
		width: 662rpx;
		margin: 130rpx auto 90rpx auto;
		background: #ab61ff;
		border-radius: 40rpx;
		border: 0;
		color: #fff;

		&.u-hairline-border:after {
			border: 0;
		}
	}

	.word {
		font-size: 36rpx;
		color: #0d1d36;
		font-weight: bold;
	}

	.list {
		// border: 1px solid;
		width: 690rpx;
		margin: 0 auto;
		background: #F8F8FC;
		border-radius: 20px;

		.title {
			font-size: 34rpx;
			color: #0E1E36;
			font-weight: bold;
		}


		image {
			width: 36rpx;
			height: 32rpx;
		}

		.u-cell {
			padding-left: 0;
			padding-right: 0;
		}

		.add {
			// width: 140rpx;
			height: 54rpx;
			line-height: 54rpx;
			border: 2rpx solid #FF9E21;
			border-radius: 27rpx;
			font-size: 30rpx;
			color: #FF9E21;
		}

		.yuanjiao {
			width: 32rpx;
			height: 32rpx;
			line-height: 32rpx;
			background: #AB61FF;
			border-radius: 50%;
			text-align: center;
			font-size: 22rpx;
			color: #FFFFFF;
			position: relative;
			top: 70rpx;

		}
	}
	.qtsm{
		display: flex;
		align-items: center;
		.hz{
			color: #0D1D36;
			font-size: 30rpx;
			margin-left: 15rpx;
		}
	}
	.zwpj{
			width: 690rpx;
			height: 260rpx;
			background-color: #F5F5F9;
			margin-top: 40rpx;
			font-size: 30rpx;
			color: #F5F5F9;
			border-radius: 10rpx;
			line-height: 44rpx;
		}
</style>
